package WordGame;
import java.util.Random;

/**
 * @Author quan
 * @Description 面向对象的总和案例1：文字版格斗
 * @Date 2023/1/22 20:17
 */

//javabean类
public class Role {
    //定义成员变量
    private String name;
    private int blood;
    private char gender;
    private String face;
    String[] boyface={"风流倜傥","气宇轩昂","相貌英俊","五官端正","相貌平平","一塌糊涂","面目狰狞"};
    String[] girlface={"美轮美奂","身材姣好","婷婷玉立","沉鱼落雁","相貌平平","一塌糊涂","面目狰狞"};

    String[] attacks_desc = {
            "%s使出了一招【背心钉】，转到对方身后，一掌向%s的灵台穴拍去",
            "%s使出了一招【dakcn】，转到对方身后，一掌向%s的dwad c拍去",
            "%s使出了一招【alncs】，转到对方身后，一掌向%s的dankdn 拍去",
            "%s使出了一招【dsanil】，转到对方身后，一掌向%s的saccd拍去",
            "%s使出了一招【cnaold】，转到对方身后，一掌向%s的dsacdzs拍去"

    };

    String[] injured_desc = {
            "%s毫发无伤",
            "%s沙石堡才开始",
            "%s从十进制",
            "%s按时吃的啥",
            "%s是安慰巨星陈"

    };

    //定义构造方法（空的和带参数的）
    public Role() {
    }

    public Role(String name, int blood, char gender) {
        this.name = name;
        this.blood = blood;
        this.gender = gender;
        setFace(gender);
    }

    //对每一个成员变量都生成set和get方法
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getBlood() {
        return blood;
    }

    public void setBlood(int blood) {
        this.blood = blood;
    }

    public char getGender() {
        return gender;
    }

    public void setGender(char gender) {
        this.gender = gender;
    }

    public String getFace() {
        return face;
    }

    public void setFace(char gender) {
        //设置随机长相：男与女
        Random r = new Random();
        if(gender=='男'){
            int index = r.nextInt(boyface.length);
            //通过索引获取长相并赋值
            this.face = boyface[index];
        }else if(gender=='女'){
            int index = r.nextInt(girlface.length);
            this.face = girlface[index];
        }else{
            this.face = "貌美如花";
        }
       //默认生成的去掉，因为自己上面重新设置了 this.face = face;
    }

    //方法1：自己构造一个”攻击“的方法:方法的调用者去攻击参数
    //1、方法的调用者是this？？？,参数是Role role,传入的参数；
    public void attack(Role role){
        //攻击描述
        Random r = new Random();
        int index = r.nextInt(attacks_desc.length);
        String KungFu = attacks_desc[index];
        System.out.printf(KungFu,this.getName(),role.getName());
        System.out.println();

        //计算造成的伤害
        int hurt = r.nextInt(20)+1;
        //修改挨揍人的血量
        int remainblood = role.getBlood()-hurt;
        remainblood = remainblood < 0? 0:remainblood;
        //更新挨揍人的血量
        role.setBlood(remainblood);

        //受伤描述：根据血量多少判断使用哪条受伤情况
        if(remainblood<90){
            System.out.printf(injured_desc[0],role.getName());
        } else if (remainblood>80) {
            System.out.printf(injured_desc[1],role.getName());
        } else if (remainblood>60) {
            System.out.printf(injured_desc[2],role.getName());
        } else if (remainblood>40) {
            System.out.printf(injured_desc[3],role.getName());
        }else{
            System.out.printf(injured_desc[4],role.getName());
        }
        System.out.println();
    }

    //方法2：展示角色的信息
    public void showRoleInfo(){
        System.out.println("姓名为："+getName());
        System.out.println("血量为："+getBlood());
        System.out.println("性别为："+getGender());
        System.out.println("长相为："+getFace());
    }
}
